<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Electron," />










<meta name="description" content="之前写桌面程序基本上用的都是易语言，而最近一哥们给推荐了Electron，感觉不错，优点呢，就是跨平台，稳定。要说明的是，我是技术小白，写这个纯粹的是记录一下，以便以后使用。 我使用的是Electron+Vue+Element-ui的组合 废话不多说了，直接开始吧，首先需要安装Node.js，这个就不记录了，官网安装就行，安装好以后，首先就是要做淘宝的镜像，要不，慢的你找不到南北 基础环境配置以下">
<meta property="og:type" content="article">
<meta property="og:title" content="架设Electron+Vue+Element-ui桌面应用记录">
<meta property="og:url" content="http://www.ziyouyu.cn/2020/05/17/electron/index.html">
<meta property="og:site_name" content="自由鱼-栗士杰个人博客">
<meta property="og:description" content="之前写桌面程序基本上用的都是易语言，而最近一哥们给推荐了Electron，感觉不错，优点呢，就是跨平台，稳定。要说明的是，我是技术小白，写这个纯粹的是记录一下，以便以后使用。 我使用的是Electron+Vue+Element-ui的组合 废话不多说了，直接开始吧，首先需要安装Node.js，这个就不记录了，官网安装就行，安装好以后，首先就是要做淘宝的镜像，要不，慢的你找不到南北 基础环境配置以下">
<meta property="article:published_time" content="2020-05-16T17:19:42.000Z">
<meta property="article:modified_time" content="2020-05-17T02:53:23.678Z">
<meta property="article:author" content="小小鱼">
<meta property="article:tag" content="Electron">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.ziyouyu.cn/2020/05/17/electron/"/>





  <title>架设Electron+Vue+Element-ui桌面应用记录 | 自由鱼-栗士杰个人博客</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?13bf495e8be3c4380c62793cc3758920";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">自由鱼-栗士杰个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/me.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.ziyouyu.cn/2020/05/17/electron/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="小小鱼">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="自由鱼-栗士杰个人博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">架设Electron+Vue+Element-ui桌面应用记录</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-17T01:19:42+08:00">
                2020-05-17
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>之前写桌面程序基本上用的都是易语言，而最近一哥们给推荐了Electron，感觉不错，优点呢，就是跨平台，稳定。要说明的是，我是技术小白，写这个纯粹的是记录一下，以便以后使用。</p>
<p>我使用的是Electron+Vue+Element-ui的组合</p>
<p>废话不多说了，直接开始吧，首先需要安装Node.js，这个就不记录了，官网安装就行，安装好以后，首先就是要做淘宝的镜像，要不，慢的你找不到南北</p>
<h1 id="基础环境配置"><a href="#基础环境配置" class="headerlink" title="基础环境配置"></a>基础环境配置</h1><h2 id="以下命令是使用国内的淘宝镜像"><a href="#以下命令是使用国内的淘宝镜像" class="headerlink" title="以下命令是使用国内的淘宝镜像"></a>以下命令是使用国内的淘宝镜像</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm config <span class="built_in">set</span> registry https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure>

<h2 id="验证命令"><a href="#验证命令" class="headerlink" title="验证命令"></a>验证命令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm config get registry</span><br></pre></td></tr></table></figure>

<h2 id="安装cnpm"><a href="#安装cnpm" class="headerlink" title="安装cnpm"></a>安装cnpm</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g cnpm</span><br></pre></td></tr></table></figure>

<h2 id="再安装yarn，这个很重要"><a href="#再安装yarn，这个很重要" class="headerlink" title="再安装yarn，这个很重要"></a>再安装yarn，这个很重要</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ cnpm install -g yarn</span><br></pre></td></tr></table></figure>

<h2 id="安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装"><a href="#安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装" class="headerlink" title="安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装"></a>安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ cnpm install -g @vue/cli</span><br></pre></td></tr></table></figure>

<h1 id="创建工程项目"><a href="#创建工程项目" class="headerlink" title="创建工程项目"></a>创建工程项目</h1><h2 id="到项目文件夹，创建vue工程"><a href="#到项目文件夹，创建vue工程" class="headerlink" title="到项目文件夹，创建vue工程"></a>到项目文件夹，创建vue工程</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vue create <span class="built_in">test</span>&lt;创建的工程目录&gt;</span><br></pre></td></tr></table></figure>
<p>我选择的都是是默认，根据需要而定吧</p>
<h2 id="安装Electron"><a href="#安装Electron" class="headerlink" title="安装Electron"></a>安装Electron</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vue add electron-builder</span><br></pre></td></tr></table></figure>
<p>首次安装或许会慢点，耐心等待安装完成就行</p>
<h2 id="安装及加载Element-ui"><a href="#安装及加载Element-ui" class="headerlink" title="安装及加载Element-ui"></a>安装及加载Element-ui</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i element-ui -S</span><br></pre></td></tr></table></figure>
<p>这里，我使用了npm安装，没有使用cnpm，有机会下次试试<br>在工程目录下src/main.js中添加如下代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// element-ui</span><br><span class="line">import ElementUI from <span class="string">'element-ui'</span></span><br><span class="line">import <span class="string">'element-ui/lib/theme-chalk/index.css'</span></span><br><span class="line">Vue.use(ElementUI)</span><br></pre></td></tr></table></figure>
<p>可以从Element-ui中随便挑选一个，测试一下</p>
<h2 id="到这里，基本上安装完成了，执行如下命令，就能看调试了"><a href="#到这里，基本上安装完成了，执行如下命令，就能看调试了" class="headerlink" title="到这里，基本上安装完成了，执行如下命令，就能看调试了"></a>到这里，基本上安装完成了，执行如下命令，就能看调试了</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ yarn electron:serve</span><br></pre></td></tr></table></figure>
<h2 id="如果需要编译的话，就是如下命令"><a href="#如果需要编译的话，就是如下命令" class="headerlink" title="如果需要编译的话，就是如下命令"></a>如果需要编译的话，就是如下命令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ yarn electron:build</span><br></pre></td></tr></table></figure>
<h1 id="其他备注"><a href="#其他备注" class="headerlink" title="其他备注"></a>其他备注</h1><blockquote>
<p>需要注意的问题，默认安装的Electron版本为6.0.0,需要在package.json中更改</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"electron"</span>: <span class="string">"^8.2.5"</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>再执行 cnpm install 就行</p>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Electron/" rel="tag"># Electron</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/05/15/hello-world/" rel="next" title="Hello World">
                <i class="fa fa-chevron-left"></i> Hello World
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/05/17/baidutongji/" rel="prev" title="HEXO-next主题添加百度统计功能">
                HEXO-next主题添加百度统计功能 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="小小鱼" />
            
              <p class="site-author-name" itemprop="name">小小鱼</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                左邻右舍
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.baidu.com/" title="百度" target="_blank">百度</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#基础环境配置"><span class="nav-number">1.</span> <span class="nav-text">基础环境配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#以下命令是使用国内的淘宝镜像"><span class="nav-number">1.1.</span> <span class="nav-text">以下命令是使用国内的淘宝镜像</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#验证命令"><span class="nav-number">1.2.</span> <span class="nav-text">验证命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装cnpm"><span class="nav-number">1.3.</span> <span class="nav-text">安装cnpm</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#再安装yarn，这个很重要"><span class="nav-number">1.4.</span> <span class="nav-text">再安装yarn，这个很重要</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装"><span class="nav-number">1.5.</span> <span class="nav-text">安装完cnpm后，需要安装vue脚手架，用的是cnpm命令安装</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#创建工程项目"><span class="nav-number">2.</span> <span class="nav-text">创建工程项目</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#到项目文件夹，创建vue工程"><span class="nav-number">2.1.</span> <span class="nav-text">到项目文件夹，创建vue工程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装Electron"><span class="nav-number">2.2.</span> <span class="nav-text">安装Electron</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装及加载Element-ui"><span class="nav-number">2.3.</span> <span class="nav-text">安装及加载Element-ui</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#到这里，基本上安装完成了，执行如下命令，就能看调试了"><span class="nav-number">2.4.</span> <span class="nav-text">到这里，基本上安装完成了，执行如下命令，就能看调试了</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#如果需要编译的话，就是如下命令"><span class="nav-number">2.5.</span> <span class="nav-text">如果需要编译的话，就是如下命令</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#其他备注"><span class="nav-number">3.</span> <span class="nav-text">其他备注</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小小鱼</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
